package org.aeon.client.view.components.menuPanel;

import org.aeon.client.context.GlobalContext;
import org.aeon.message.request.CancelLoginRequestMessage;
import org.aeon.utils.SimpleRequestUtil;
import org.aeon.utils.SwingUtil;

import javax.swing.*;
import javax.swing.border.Border;
import java.awt.*;
import java.awt.event.FocusAdapter;
import java.awt.event.FocusEvent;

/**
 * @author: MissingAeon
 * @date: 2024/2/22 19:04
 * @description:
 */
public class SettingsOptionDialog extends JPanel {
    public static SettingsOptionDialog settingsOptionDialog = new SettingsOptionDialog();

    public SettingsOptionDialog() {
        SwingUtil.setSize(this, new Dimension(180, 45));
        // 设置位置

        final Border border = BorderFactory.createMatteBorder(1, 1, 1, 1, Color.LIGHT_GRAY);
        this.setBackground(new Color(0xDEDEDE));
        this.setBorder(border);
        this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
        final JButton button = new JButton("退出登录");
        SwingUtil.removeStyle2(button);
        SwingUtil.setSize(button, new Dimension(180, 40));
        this.add(button);

        this.addFocusListener(new FocusAdapter() {
            @Override
            public void focusLost(FocusEvent e) {
                GlobalContext.getContext().getMainUI().removePopUpLayer(SettingsOptionDialog.this);
            }
        });

        button.addActionListener(e -> {
            System.out.println(111);
            final GlobalContext context = GlobalContext.getContext();
            SimpleRequestUtil.send(context, new CancelLoginRequestMessage());
        });
    }

    public static SettingsOptionDialog createDialog(Component comp) {
        settingsOptionDialog.setBounds(comp.getWidth() - 5, comp.getY(), 180, 45);
        settingsOptionDialog.requestFocus();
        return settingsOptionDialog;
    }
}
